package com.aioz.security.controller;


import com.aioz.security.aop.annotation.LogInfoAnnotation;
import com.aioz.security.common.ResponseResult;
import com.aioz.security.entity.Application;
import com.aioz.security.entity.Resume;
import com.aioz.security.service.impl.ApplicationServiceImpl;
import com.aioz.security.service.impl.ResumeServiceImpl;
import com.aioz.security.service.impl.UserServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Aioz
 * @since 2022-09-27
 */
@RestController
@RequestMapping("/resume")
@Slf4j
public class ResumeController {

    @Resource
    private ResumeServiceImpl resumeService;

    @Resource
    private UserServiceImpl userService;

    @Resource
    private ApplicationServiceImpl applicationService;

    // 添加简历信息
    @PostMapping("/add")
    @LogInfoAnnotation
    public ResponseResult addResume(@RequestBody Resume resume){
        return resumeService.addResume(resume);
    }

    // 修改简历信息
    @PostMapping("/update")
    @LogInfoAnnotation
    public ResponseResult updateResume(@RequestBody Resume resume){
        return resumeService.updateResume(resume);
    }

    //根据resumeId获取用户详细信息
    @PostMapping("/get/info/{id}")
    @LogInfoAnnotation
    public ResponseResult getInfoByResumeId(@PathVariable Integer id){
        Application application = applicationService.getById(id);
        if( 1 == application.getState()){
            application.setState(application.getState()+1);
            applicationService.updateById(application);
        }
        log.info("用户ID {}",application.getUserId());
        return userService.getResumeInfo(application.getUserId());
    }
}
